//
//  VisitorLoginView.swift
//  SinaWeibo25
//
//  Created by David on 16/3/5.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import SnapKit


class VisitorLoginView: UIView {

//    init() {
//        //指定,专门设计的构造器
//       super.init(frame: CGRectZero)
//    }
    
   //要自定义视图 首先找到入口
    override init(frame: CGRect) {
        //super
         super.init(frame: frame)
        
        //访客视图的自定义
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //MARK: 自定义访客视图
    private func setUpUI() {
        
        addSubview(circleIcon)
        addSubview(largeHouse)
        //VFL  使用父视图添加约束对象
        /*
        1.item: 需要添加约束的对象
        2.attribute: 对象需要添加约束的属性
        3.relatedBy: 对其方式 一般使用精准约束的方式
        4.toItem: 布局相对应的视图 参照视图
        5.attribute: 参照对象约束属性
        6.multiplier: 乘积系数  一般使用 1
        7.constant: 约束的偏移量
        
        "view1.attr1 = view2.attr2 * multiplier + constant"
        */
        //在手写代码添加自动布局约束对象时候 需要禁用frame布局
//        circleIcon.translatesAutoresizingMaskIntoConstraints = false
//        self.addConstraint(NSLayoutConstraint(item: circleIcon, attribute: NSLayoutAttribute.CenterX, relatedBy: .Equal, toItem: self, attribute: .CenterX, multiplier: 1, constant: 0))
//        self.addConstraint(NSLayoutConstraint(item: circleIcon, attribute: NSLayoutAttribute.CenterY, relatedBy: .Equal, toItem: self, attribute: .CenterY, multiplier: 1, constant: 0))
        //布局 需要相对于一个已经约束好的视图来添加 链式布局
        circleIcon.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.snp_centerX)
            make.centerY.equalTo(self.snp_centerY).offset(-80)
//            make.center.equalTo(self.snp_center)
        }
        
        largeHouse.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(circleIcon.snp_center)
        }
    }
    
    
    //懒加载子视图
    private lazy var circleIcon: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    
    //大房子
    private lazy var largeHouse: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    
    private lazy var tipLabel: UILabel = {
        let l = UILabel()
        l.text = "关注一些人,回到这里看看有什么惊喜"
        l.textColor = UIColor.darkGrayColor()
        l.font = UIFont.systemFontOfSize(14)
        
        //自适应大小
        l.sizeToFit()
        
        
        return l
    }()
    
    //登录和注册按钮
    private lazy var loginBtn: UIButton = {
        let btn = UIButton()
        //这是背景图片
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
        btn.setTitle("登录", forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        btn.sizeToFit()
        return btn
        
    }()
    
    
    private lazy var registerBtn: UIButton = {
        let btn = UIButton()
        //这是背景图片
        btn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState: .Normal)
        btn.setTitle("注册", forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        btn.sizeToFit()
        return btn
        
    }()
    
    

}
